package com.sun.showcase.controller.app.mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aliyuncs.utils.StringUtils;
import com.sun.showcase.biz.mall.service.MemberCashApplyService;
import com.sun.showcase.client.domain.mall.MemberCashApply;
import com.sun.showcase.client.query.mall.MemberCashApplyQuery;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.utils.ExecuteResult;

@RestController("appMemberCashApplyController")
@RequestMapping(value="/app/memberCashApply") 
public class MemberCashApplyController{
	
	@Autowired
	private MemberCashApplyService memberCashApplyService;
	
	private Result result = new Result();
	
	@RequestMapping(value="apply")
	public Result apply(MemberCashApplyQuery memberCashApplyQuery) {
		ExecuteResult<MemberCashApply> res = memberCashApplyService.save(memberCashApplyQuery);
		result.setSuccess(res.isSuccess());
		if(res.isSuccess()) {
			result.setMsg(res.getSuccessMessage());
			result.setData(res.getResult());
		}else {
			result.setMsg(res.getErrorMessages().get(0));
		}
		return result;
	}
	
	@RequestMapping(value="list")
	public Result list(MemberCashApplyQuery memberCashApplyQuery) {
		if(StringUtils.isEmpty(memberCashApplyQuery.getUserId())) {
			result.setSuccess(false);
			result.setMsg("无效用户");
			return result;
		}
		memberCashApplyQuery.setOrderColum("create_date");
		DataGrid dg = memberCashApplyService.datagrid(memberCashApplyQuery);
		result.setSuccess(true);
		result.setData(dg);
		return result;
	}
}
